// pages/detail/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      '/imgs/goods/100nrf2.jpg',
      '/imgs/goods/chaoneng2.jpg',
      '/imgs/goods/diao2.jpg',
      '/imgs/goods/jsb2.jpg'
    ],
    indicatorDots: true,
    autoplay: true,
    interval: 2000,
    duration: 2000,
    good_sale_price:  126,
    good_promotition_price: 12.6,
    good_desc: '[说的啥话都] 没看见吧查不出没看见吧查不出没看见吧查不出 100 ml',
    goodImgList:[
      { good_image_detail_url:'/imgs/goods/100nrf2.jpg'},
      { good_image_detail_url: '/imgs/goods/chaoneng2.jpg'},
      { good_image_detail_url: '/imgs/goods/mgj2.jpg'},
      { good_image_detail_url: '/imgs/goods/diao2.jpg'},
      { good_image_detail_url: '/imgs/goods/jsb2.jpg'}
    ],
    cartCount:0,
    cartCountCss:'cart-count-hidden'
  },

  gotoOderPage:function(){
    wx.navigateTo({
      url: '/pages/order/index'
    })
  },

  gotoCartPage:function(){
    wx.switchTab({
      url:'/pages/cart/index'
    })
  },

  gotoAddPage:function(){
    wx.navigateTo({
      url: '/pages/add/index'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '商品详情',
      success: function (res) {
        // success
      }
    })
    var cookies = wx.getStorageInfoSync().keys;
    var cartCount = 0 ;
    for (var k in cookies) {
      var obj = wx.getStorageSync(cookies[k]);
      if (obj.goodCount){
        cartCount += obj.goodCount
      }
    }
    if (cartCount == 0){
      this.setData({
        cartCountCss: 'cart-count-hidden'
      })
    }else{
      this.setData({
        cartCountCss: 'cart-count-show'
      })
    }
    this.setData({
      cartCount: cartCount
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})